const Mongoose = require('mongoose')
// const conn = Mongoose.createConnection("mongodb://liu:ting@localhost:27017/liuting", {
//   useNewUrlParser: true,
//   useUnifiedTopology: true
// })

// http://106.12.132.55:27017/
const conn = Mongoose.createConnection("mongodb://localhost:27017/liuting", {
  useNewUrlParser:true,
  useUnifiedTopology: true
})

conn.on('open',  console.log.bind(console, '连接成功！！'))
conn.on('error',  console.log.bind(console, '连接成功！！'))

let Schema = new Mongoose.Schema({
  list: Number | String,
  createAt: {
    type: Date,
    default: Date.now
  }
}, /* { collection: 'p' } */) // 不指定 默认当前集合名小写 + s

let Product = conn.model('liutings', Schema)

Product.create({list: '这是新创建的' }).then(res => {
  console.log(res)
})

Product.find().then(res => {
  console.log('result', res)
})


// Product.insertMany({ list: 'insetrt' }).then(res => { // 插入数组
//   console.log(res)
// })


// Product.updateOne({ list: '这是新创建的' }, { list: '新建' }).then(res =>{
//   console.log(res)
// })

// Product.deleteOne({ list:'这是新创建的' }).then(res => {
//   console.log(res)
// })
